package com.dailyblue.java.spring.boot.mvc.mybatis.handler;

import com.dailyblue.java.spring.boot.commons.exception.NotLoginException;
import com.dailyblue.java.spring.boot.commons.exception.UserCodeNotFoundException;
import com.dailyblue.java.spring.boot.commons.exception.UserPasswordErrorException;
import com.dailyblue.java.spring.boot.commons.util.JsonResult;
import com.dailyblue.java.spring.boot.commons.util.ResultCode;
import com.dailyblue.java.spring.boot.commons.util.ResultTool;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(UserCodeNotFoundException.class)
    public JsonResult userCodeNotFound() {
        return ResultTool.fail(ResultCode.USER_ACCOUNT_NOT_EXIST);
    }

    @ExceptionHandler(UserPasswordErrorException.class)
    public JsonResult passwordError() {
        return ResultTool.fail(ResultCode.USER_CREDENTIALS_ERROR);
    }

    @ExceptionHandler(NotLoginException.class)
    public JsonResult notLogin() {
        return ResultTool.fail(ResultCode.USER_NOT_LOGIN);
    }
}
